/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pb138.mathml_canonicalizator;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Richard
 */
public class MfracTransformer implements Transformer {
    
    private Node root;
    // private static final String configFile = "src/mfrac.properties";

    public MfracTransformer(String tagName, Map<String,String> attrs,
            Map<String, List<String>> properties) {
        
        // can be null
        // List<String> attr_keep = properties.get("attr_keep");
        
        List<String> attr_keep = properties.get("attr_keep") != null ?
                properties.get("attr_keep") : new ArrayList<String>();
        
        // removes all attributes that should be removed
        Util.removeAtrributes(attrs, attr_keep);
        
        // special case
        if (attrs.keySet().contains("linethickness")) {
            String value = attrs.get("linethickness");
            attrs.remove("linethickness");
            attrs.put("linethickness", value.equals("0") ? "0" : "1");
        } else if (attr_keep.contains("linethickness")) {
            attrs.put("linethickness", "1");
        }
        
        root = new NodeImpl(tagName, attrs);
    }

    @Override
    public void addChild(Node n) {
        root.addChild(n);
    }

    @Override
    public void setTextContent(String s) {
    }

    @Override
    public Node transform() {
        return root;
    }
}
